﻿


using System;
using System.Collections.Generic;
using System.Web;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using Payroll.BusinessLogic.CustomerManager;
using Payroll.Common.Utils.Html;
using Payroll.Common.Utils;
using PdfSharp.Drawing;
using System.Text;
using System.Drawing;
using MigraDoc.DocumentObjectModel.Shapes;

namespace Payroll.BusinessLogic.Utils
{
    /// <summary>
    /// Represents a PDF helper
    /// </summary>
    public partial class PDFHelper
    {
        protected static string m_urlImage = CommonHelper.GetStoreLocation() + "images\\LogoOsiVietNam.jpg";
        #region Methods
        public static Document PrintCustomerToPdf(Customer customer, List<FeesSchedule> List, string filePath, string urlImage = "")
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            Document doc = new Document();
            doc.Info.Title = "Customer Info";
            doc.Info.Subject = "Create an customer.";
            doc.Info.Author = "OSIVIETNAM";
            //doc.DefaultPageSetup.MirrorMargins = true;
            doc.DefaultPageSetup.LeftMargin = "5mm";
            doc.DefaultPageSetup.RightMargin = "5mm";
            //doc.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            doc.DefaultPageSetup.TopMargin = "38mm";
            doc.DefaultPageSetup.BottomMargin = "5mm";
            doc.DefaultPageSetup.PageFormat = PageFormat.A4;

            Section section = doc.AddSection();
            #region Info
            ///image
            Paragraph paraHeader = section.Headers.Primary.AddParagraph();
            paraHeader.AddImage(urlImage);
            paraHeader.Format.Alignment = ParagraphAlignment.Center;

            //Tile
            Paragraph paraTitle = section.AddParagraph("CUSTOMER’ S INFORMATION");
            //paraTitle.AddText("CUSTOMER’ S INFORMATION");
            paraTitle.Format.Font.Size = 15;
            paraTitle.Format.Font.Bold = true;
            paraTitle.Format.Font.Color = Colors.DarkBlue;
            paraTitle.Format.Alignment = ParagraphAlignment.Center;
            #region Casework
            if (customer.MimeType.Length > 0)
            {
                Table caseWorkTable = section.AddTable();
                Column column1 = caseWorkTable.AddColumn("50mm");
                column1.Format.Alignment = ParagraphAlignment.Left;
                Column column2 = caseWorkTable.AddColumn("124mm");
                column2.Format.Alignment = ParagraphAlignment.Center;
                Row row = caseWorkTable.AddRow();
                string imgSrc = customer.imageUrl.Replace("http://cust.osivietnam.com", "~");// "~/images/ARCHeader.png";
                MigraDoc.DocumentObjectModel.Shapes.Image leftImage = row.Cells[0].AddImage(HttpContext.Current.Server.MapPath(imgSrc));
                leftImage.LockAspectRatio = true;
                leftImage.RelativeVertical = RelativeVertical.Page;
                leftImage.RelativeHorizontal = RelativeHorizontal.Page;
                leftImage.Top = ShapePosition.Top;
                leftImage.Left = ShapePosition.Left;
                leftImage.WrapFormat.Style = WrapStyle.Through;

                //Location
                //Paragraph p = row.Cells[1].AddParagraph("1.Casework #: " + customer.CustName + "\n");
                Paragraph p = row.Cells[1].AddParagraph();
                p.AddFormattedText("1.Casework #: ", TextFormat.Bold);
                p.AddFormattedText(customer.CustName, TextFormat.Italic | TextFormat.Underline);
                p.AddText("   Date: ");
                p.AddFormattedText(string.Format("{0}", customer.CustDate), TextFormat.Italic | TextFormat.Underline);
                p.AddText("   Time: ");
                p.AddFormattedText(customer.CustHour, TextFormat.Underline | TextFormat.Italic);
                p.AddLineBreak();
                p.Format.Alignment = ParagraphAlignment.Justify;
                p.Style = "H1";

                p = row.Cells[1].AddParagraph();
                p.Format.Font.Size = 10.5;
                p.Format.Alignment = ParagraphAlignment.Left;
                p.AddText("DOB: ");
                p.AddFormattedText(string.Format("{0}", customer.CustDateOfBirth), TextFormat.Italic | TextFormat.Underline);
                p.AddText("   Place: ");
                p.AddFormattedText(string.Format("{0}", customer.CustPlate), TextFormat.Italic | TextFormat.Underline);
                p.AddLineBreak();

                p.Style = "H2";
                p = row.Cells[1].AddParagraph();
                p.Format.Font.Size = 10.5;
                p.Format.Alignment = ParagraphAlignment.Left;
                p.AddText(" Họ & tên phụ huynh: ");
                p.AddFormattedText(customer.CustParent, TextFormat.Underline | TextFormat.Italic);
                p.AddLineBreak();

                p.Style = "H3";
                p = row.Cells[1].AddParagraph();
                p.Format.Font.Size = 10.5;
                p.Format.Alignment = ParagraphAlignment.Left;
                p.AddText(" Địa chỉ nhà: ");
                p.AddFormattedText(customer.CustAddres, TextFormat.Underline | TextFormat.Italic);

                p = row.Cells[1].AddParagraph();
                p.Format.Font.Size = 10.5;
                p.Format.Alignment = ParagraphAlignment.Left;
                p.AddText("ĐT(H&Mobile): ");
                p.AddFormattedText(customer.CustMobile, TextFormat.Underline | TextFormat.Italic);
                p.AddLineBreak();

                p.Style = "H4";
                p = row.Cells[1].AddParagraph();
                p.Format.Font.Size = 10.5;
                p.Format.Alignment = ParagraphAlignment.Left;
                p.AddText(" Địa chỉ sở làm/trường học: ");
                p.AddFormattedText(customer.CustCompany, TextFormat.Underline | TextFormat.Italic);
                p.AddText("   ĐT(W): ");
                p.AddFormattedText(customer.CustPhone, TextFormat.Underline | TextFormat.Italic);
                p.AddLineBreak();

                p.Style = "H5";
                p = row.Cells[1].AddParagraph();
                p.Format.Font.Size = 10.5;
                p.Format.Alignment = ParagraphAlignment.Left;
                p.AddText(" Email: ");
                p.AddFormattedText(customer.CustEmail, TextFormat.Underline | TextFormat.Italic);
                p.AddText("   Fax: ");
                p.AddFormattedText(customer.CustFax, TextFormat.Underline | TextFormat.Italic);
                p.AddLineBreak();

                //p.Format.Font.Bold = true;
                //p.Format.Font.Size = 12;
            }
            else
            {
                Paragraph p1 = doc.LastSection.AddParagraph();
                p1.Format.Alignment = ParagraphAlignment.Justify;
                p1.Format.Font.Size = 10.5;
                p1.AddFormattedText("1.Casework #: ", TextFormat.Bold);
                p1.AddFormattedText(customer.CustName, TextFormat.Italic | TextFormat.Underline);
                p1.AddText("   Date: ");
                p1.AddFormattedText(string.Format("{0}", customer.CustDate), TextFormat.Italic | TextFormat.Underline);
                p1.AddText("   Time: ");
                p1.AddFormattedText(customer.CustHour, TextFormat.Underline | TextFormat.Italic);
                p1.AddLineBreak();

                Paragraph p2 = doc.LastSection.AddParagraph();
                p2.Format.Font.Size = 10.5;
                p2.AddText("DOB: ");
                p2.AddFormattedText(string.Format("{0}", customer.CustDateOfBirth), TextFormat.Italic | TextFormat.Underline);
                p2.AddText("   Place: ");
                p2.AddFormattedText(string.Format("{0}", customer.CustPlate), TextFormat.Italic | TextFormat.Underline);
                p2.AddLineBreak();

                Paragraph p3 = doc.LastSection.AddParagraph();
                p3.Format.Font.Size = 10.5;
                p3.AddText(" Họ & tên phụ huynh: ");
                p3.AddFormattedText(customer.CustParent, TextFormat.Underline | TextFormat.Italic);
                p3.AddLineBreak();


                Paragraph p4 = doc.LastSection.AddParagraph();
                p4.Format.Font.Size = 10.5;
                p4.AddText(" Địa chỉ nhà: ");
                p4.AddFormattedText(customer.CustAddres, TextFormat.Underline | TextFormat.Italic);
                p4.AddText("   ĐT(H&Mobile): ");
                p4.AddFormattedText(customer.CustMobile, TextFormat.Underline | TextFormat.Italic);
                p4.AddLineBreak();

                Paragraph p5 = doc.LastSection.AddParagraph();
                p5.Format.Font.Size = 10.5;
                p5.AddText(" Địa chỉ sở làm/trường học: ");
                p5.AddFormattedText(customer.CustCompany, TextFormat.Underline | TextFormat.Italic);
                p5.AddText("   ĐT(W): ");
                p5.AddFormattedText(customer.CustPhone, TextFormat.Underline | TextFormat.Italic);
                p5.AddLineBreak();

                Paragraph p6 = doc.LastSection.AddParagraph();
                p6.Format.Font.Size = 10.5;
                p6.AddText(" Email: ");
                p6.AddFormattedText(customer.CustEmail, TextFormat.Underline | TextFormat.Italic);
                p6.AddText("   Fax: ");
                p6.AddFormattedText(customer.CustFax, TextFormat.Underline | TextFormat.Italic);
                p6.AddLineBreak();
            }
            #endregion
            #region 2.Source
            Paragraph p8 = doc.LastSection.AddParagraph();
            p8.Format.Font.Size = 10.5;
            p8.AddFormattedText("2.Source: ", TextFormat.Bold);
            //Paragraph p8 = doc.LastSection.AddParagraph();
            p8.AddFormattedText(customer.CustSource, TextFormat.Italic | TextFormat.Underline);
            p8.AddLineBreak();

            p8.AddText("Đã từng bị từ chối visa chưa ?: ");
            if (customer.isVisa == true)
            {
                p8.AddFormattedText("Có.", TextFormat.Italic | TextFormat.Underline);
            }
            else
            {
                p8.AddFormattedText("Chưa.", TextFormat.Italic | TextFormat.Underline);
            }
            p8.AddFormattedText(string.Format(" Số lần bị từ chối: {0}", customer.VisaNumber), TextFormat.Italic);
            p8.AddLineBreak();

            p8.AddText(" Lý do:");
            p8.AddFormattedText(string.Format("{0}", customer.TravelNote), TextFormat.Italic | TextFormat.Underline);
            p8.AddLineBreak();
            #endregion
            Paragraph p9 = doc.LastSection.AddParagraph();
            p9.Format.Font.Size = 10.5;
            p9.AddText(" Đã từng đến các nước (&cả gia đinh): ");
            p9.AddFormattedText(customer.SourceToNation, TextFormat.Underline | TextFormat.Italic);

            Paragraph p10 = doc.LastSection.AddParagraph();
            p10.Format.Font.Size = 10.5;
            p10.AddText(" Có hồ sơ bảo lãnh định cư không? ");
            p10.AddFormattedText(string.Format("{0}", customer.SourcePetition ? "Có" : "Không"), TextFormat.Underline | TextFormat.Italic);

            p10.AddLineBreak();

            Paragraph p11 = doc.LastSection.AddParagraph();
            p11.Format.Font.Size = 10.5;
            p11.AddFormattedText("3.QT Học tập: ", TextFormat.Bold);
            p11.AddText(" TN C2 năm: ");
            p11.AddFormattedText(string.Format("{0}", customer.ProBaccalaureate), TextFormat.Underline | TextFormat.Italic);
            p11.AddText("   TN C3 năm: ");
            p11.AddFormattedText(string.Format("{0}", customer.ProGraduateYear), TextFormat.Underline | TextFormat.Italic);
            p11.AddText("   CT Khác: ");
            p11.AddFormattedText(customer.ProLearning, TextFormat.Underline | TextFormat.Italic);
            p11.AddLineBreak();

            Paragraph p12 = doc.LastSection.AddParagraph();
            p12.Format.Font.Size = 10.5;
            p12.AddText("Học lực: ");
            p12.AddFormattedText(customer.CustEdu, TextFormat.Underline | TextFormat.Italic);
            p12.AddText(" KN Anh ngữ: ");
            p12.AddFormattedText(customer.CustLangue, TextFormat.Underline | TextFormat.Italic);
            p12.AddText("   Công việc hiện tại: ");
            p12.AddFormattedText(customer.ProWorking, TextFormat.Underline | TextFormat.Italic);

            p12.AddLineBreak();

            Paragraph p13 = doc.LastSection.AddParagraph();
            p13.Format.Font.Size = 10.5;
            p13.AddFormattedText("4.", TextFormat.Bold);
            p13.AddText("Du học: ");
            if (customer.IsStudy == 0)
            {
                p13.AddFormattedText(" Có", TextFormat.Underline | TextFormat.Italic);
            }
            p13.AddText("   Du Lịch: ");
            if (customer.IsStudy == 1)
            {
                p13.AddFormattedText(" Có", TextFormat.Underline | TextFormat.Italic);
            }
            p13.AddText("   Đ/cư: ");
            if (customer.IsStudy == 2)
            {
                p13.AddFormattedText(" Có", TextFormat.Underline | TextFormat.Italic);
            }
            p13.AddText("   Nước: ");
            p13.AddFormattedText(customer.CustNationalName, TextFormat.Underline | TextFormat.Italic);
            p13.AddText("   State: ");
            p13.AddFormattedText(customer.CustState, TextFormat.Underline | TextFormat.Italic);
            p13.AddText("   City: ");
            p13.AddFormattedText(customer.CustCity, TextFormat.Underline | TextFormat.Italic);
            p13.AddLineBreak();

            Paragraph p14 = doc.LastSection.AddParagraph();
            p14.Format.Font.Size = 10.5;
            p14.AddText("Ngành học: ");
            p14.AddFormattedText(customer.ProGraduateIndustry, TextFormat.Underline | TextFormat.Italic);
            p14.AddText("   Cấp học:");
            p14.AddFormattedText(customer.CustLevel, TextFormat.Underline | TextFormat.Italic);
            p14.AddLineBreak();

            Paragraph p15 = doc.LastSection.AddParagraph();
            p15.Format.Font.Size = 10.5;
            p15.AddText("Trường học: ");
            p15.AddFormattedText(customer.ProSchool, TextFormat.Underline | TextFormat.Italic);
            p15.AddText("   Nhân viên phụ trách: ");
            p15.AddFormattedText(customer.ProCurator, TextFormat.Underline | TextFormat.Italic);
            p15.AddLineBreak();
            Paragraph p45 = doc.LastSection.AddParagraph();
            p45.Format.Font.Size = 10.5;
            p45.AddText("Họ, tên & địa chỉ thân nhân ở nước ngoài: ");
            p45.AddFormattedText(customer.CustRelative, TextFormat.Underline | TextFormat.Italic);
            p45.AddText(" - ");
            p45.AddFormattedText(customer.CustRelativeAddre, TextFormat.Underline | TextFormat.Italic);

            p45.AddLineBreak();

            Paragraph p46 = doc.LastSection.AddParagraph();
            p46.Format.Font.Size = 10.5;
            p46.AddFormattedText("5.Chứng minh tài chính: ", TextFormat.Bold);
            p46.AddLineBreak();
            p46.AddText("Loại hình kinh doanh: ");
            p46.AddFormattedText(string.Format("{0}", customer.businesstype), TextFormat.Italic | TextFormat.Underline);
            p46.AddText("   Thông tin bất động sản: ");
            p46.AddFormattedText(string.Format("{0}", customer.busRealEstateInfo), TextFormat.Italic | TextFormat.Underline);
            p46.AddLineBreak();
            p46.AddText("Thuế hàng tháng: ");
            p46.AddFormattedText(string.Format("{0}", customer.busRealMonthlyTax), TextFormat.Italic | TextFormat.Underline);
            p46.AddText("   Thu nhập (tháng): ");
            p46.AddFormattedText(string.Format("{0}", customer.busMontlyIncome), TextFormat.Italic | TextFormat.Underline);
            p46.AddLineBreak();
            p46.AddText("Tài sản khác: ");
            p46.AddFormattedText(string.Format("{0}", customer.busOther), TextFormat.Italic | TextFormat.Underline);
            p46.AddLineBreak();
            p46.AddLineBreak();

            Paragraph p22 = doc.LastSection.AddParagraph();
            p22.Format.Font.Size = 10.5;
            p22.AddFormattedText("6.Giải thích yêu cầu Visa : ", TextFormat.Bold);
            p22.AddText("Học tập:_________");
            p22.AddText("Tài chánh:________");
            p22.AddText("(241B)R2VN:_________");
            p22.AddLineBreak();

            Paragraph p23 = doc.LastSection.AddParagraph();
            p23.Format.Font.Size = 10.5;
            p23.AddFormattedText("7.100%: ", TextFormat.Bold);
            p23.AddText("From 3 reasons=>never 100%:__________________________________");
            p23.AddLineBreak();

            Paragraph p24 = doc.LastSection.AddParagraph();
            p24.Format.Font.Size = 10.5;
            p24.AddFormattedText("8.Yêu cầu của khách hàng:", TextFormat.Bold);
            p24.AddFormattedText(string.Format("{0}", customer.requirements), TextFormat.Italic | TextFormat.Underline);
            p24.AddLineBreak();           

            Paragraph p27 = doc.LastSection.AddParagraph();
            p27.Format.Font.Size = 10.5;
            p27.AddFormattedText("9.Payment :", TextFormat.Bold);
            p27.AddText("Lần I ");
            p27.AddFormattedText(string.Format("{0} ", customer.payment_1), TextFormat.Italic | TextFormat.Underline);
            p27.AddText("   Lần II ");
            p27.AddFormattedText(string.Format("{0} ", customer.payment_2), TextFormat.Italic | TextFormat.Underline);
            p27.AddText("   STK ");
            p27.AddFormattedText(string.Format("{0} ", customer.payment_accountNumber), TextFormat.Italic | TextFormat.Underline);
            p27.AddText("   TC ");
            p27.AddFormattedText(string.Format("{0} ", customer.payment_financial), TextFormat.Italic | TextFormat.Underline);
            p27.AddText("   PV/VISA ");
            p27.AddFormattedText(string.Format("{0} ", customer.payment_PV_VISA), TextFormat.Italic | TextFormat.Underline);
            p27.AddText("   AN ");
            p27.AddFormattedText(string.Format("{0} ", customer.payment_AN), TextFormat.Italic | TextFormat.Underline);
            p27.AddText("   GD ");
            p27.AddFormattedText(string.Format("{0} ", customer.payment_GD), TextFormat.Italic | TextFormat.Underline);
            p27.AddLineBreak();

            Paragraph p28 = doc.LastSection.AddParagraph();
            p28.Format.Borders.Width = 1;
            p28.Format.Borders.Color = Colors.Black;
            p28.Format.Borders.Distance = 1;
            p28.Format.Font.Size = 10.5;
            p28.AddFormattedText("   - Paid:", TextFormat.Bold);

            var result = List.Find(delegate(FeesSchedule fs) { return fs.FeesTypeID == 19; });
            p28.AddFormattedText(string.Format("Lần I {0}$ ", CommonHelper.IsNull(result)? 0 : result.HaveToPayUSD), TextFormat.Italic | TextFormat.Underline);

            result = List.Find(delegate(FeesSchedule fs) { return fs.FeesTypeID == 20; });
            p28.AddFormattedText(string.Format("Lần II {0}$ ", CommonHelper.IsNull(result) ? 0 : result.HaveToPayUSD), TextFormat.Italic | TextFormat.Underline);

            result = List.Find(delegate(FeesSchedule fs) { return fs.FeesTypeID == 22; });
            p28.AddFormattedText(string.Format("STK {0}$ ", CommonHelper.IsNull(result) ? 0 : result.HaveToPayUSD), TextFormat.Italic | TextFormat.Underline);

            result = List.Find(delegate(FeesSchedule fs) { return fs.FeesTypeID == 21; });
            p28.AddFormattedText(string.Format("TC {0}$ ", CommonHelper.IsNull(result) ? 0 : result.HaveToPayUSD), TextFormat.Italic | TextFormat.Underline);

            result = List.Find(delegate(FeesSchedule fs) { return fs.FeesTypeID == 24; });
            p28.AddFormattedText(string.Format("PV/VISA {0}VNĐ ", CommonHelper.IsNull(result) ? 0 : result.HaveToPayVND), TextFormat.Italic | TextFormat.Underline);

            result = List.Find(delegate(FeesSchedule fs) { return fs.FeesTypeID == 25; });
            p28.AddFormattedText(string.Format("AN {0}$ ", CommonHelper.IsNull(result) ? 0 : result.HaveToPayUSD), TextFormat.Italic | TextFormat.Underline);

            result = List.Find(delegate(FeesSchedule fs) { return fs.FeesTypeID == 23; });
            p28.AddFormattedText(string.Format("GD {0}$ ", CommonHelper.IsNull(result) ? 0 : result.HaveToPayUSD), TextFormat.Italic | TextFormat.Underline);
            p28.AddLineBreak();
            

            Paragraph p29 = doc.LastSection.AddParagraph();
            p29.AddLineBreak();
            p29.Format.Font.Size = 10.5;
            p29.AddFormattedText("10.Kế hoạch:", TextFormat.Bold);
            p29.AddFormattedText(string.Format("{0}", customer.plan_plan), TextFormat.Italic | TextFormat.Underline);
            p29.AddLineBreak();

            Paragraph p32 = doc.LastSection.AddParagraph();
            p32.Format.Font.Size = 10.5;
            p32.AddFormattedText("11.Marketing :", TextFormat.Bold);
            p32.AddFormattedText(string.Format("{0}", customer.marketing), TextFormat.Italic | TextFormat.Underline);
            //p32.AddLineBreak();
            Paragraph p33 = doc.LastSection.AddParagraph();
            p33.Format.Font.Size = 10.5;
            p33.AddText("Kết quả tiếp thị: ");
            p32.AddFormattedText(string.Format("{0}", customer.marketing_results), TextFormat.Italic | TextFormat.Underline);
            p33.AddLineBreak();

            Paragraph p34 = doc.LastSection.AddParagraph();
            p34.Format.Font.Size = 10.5;
            p34.AddFormattedText("12.Ghi chú:", TextFormat.Bold);
            p34.AddFormattedText(string.Format("{0}", customer.Note_note), TextFormat.Italic | TextFormat.Underline);
            p34.AddLineBreak();

            Paragraph p36 = doc.LastSection.AddParagraph();
            p36.Format.Font.Size = 10.5;
            p36.AddFormattedText("13.Follow up:", TextFormat.Bold);
            p36.AddText(" - Date & nội dung - Face to face, fone, e-mail hay mail");
            p36.AddLineBreak();

            Paragraph p37 = doc.LastSection.AddParagraph();
            p37.Format.Font.Size = 10.5;
            p37.AddText("Date ");
            if (string.Format("{0}", customer.CustFollowUpDate01) != "")
            {
                string date1 = customer.CustFollowUpDate01.Split(';')[0] != "" ? customer.CustFollowUpDate01.Split(';')[0] : "";
                string date2 = customer.CustFollowUpDate01.Split(';')[1] != "" ? customer.CustFollowUpDate01.Split(';')[1] : "";
                if (date1 == "" && date2 == "")
                {
                    p37.AddFormattedText("", TextFormat.Underline | TextFormat.Italic);
                }
                else
                {
                    p37.AddFormattedText(String.Format("{0};{1}", date1, date2), TextFormat.Underline | TextFormat.Italic);
                }
            }
            p37.AddLineBreak();
            Paragraph p38 = doc.LastSection.AddParagraph();
            p38.Format.Font.Size = 10.5;
            p38.AddText("Date ");
            if (string.Format("{0}", customer.CustFollowUpDate02) != "")
            {
                string date1 = customer.CustFollowUpDate02.Split(';')[0] != "" ? customer.CustFollowUpDate02.Split(';')[0] : "";
                string date2 = customer.CustFollowUpDate02.Split(';')[1] != "" ? customer.CustFollowUpDate02.Split(';')[1] : "";
                if (date1 == "" && date2 == "")
                {
                    p38.AddFormattedText("", TextFormat.Underline | TextFormat.Italic);
                }
                else
                {
                    p38.AddFormattedText(String.Format("{0};{1}", date1, date2), TextFormat.Underline | TextFormat.Italic);
                }
            }
            p38.AddLineBreak();
            Paragraph p39 = doc.LastSection.AddParagraph();
            p39.Format.Font.Size = 10.5;
            p39.AddText("Date ");
            if (string.Format("{0}", customer.CustFollowUpDate03) != "")
            {
                string date1 = customer.CustFollowUpDate03.Split(';')[0] != "" ? customer.CustFollowUpDate03.Split(';')[0] : "";
                string date2 = customer.CustFollowUpDate03.Split(';')[1] != "" ? customer.CustFollowUpDate03.Split(';')[1] : "";
                if (date1 == "" && date2 == "")
                {
                    p39.AddFormattedText("", TextFormat.Underline | TextFormat.Italic);
                }
                else
                {
                    p39.AddFormattedText(String.Format("{0};{1}", date1, date2), TextFormat.Underline | TextFormat.Italic);
                }
            }
            p39.AddLineBreak();

            Paragraph p40 = doc.LastSection.AddParagraph();
            p40.Format.Font.Size = 10.5;
            p40.AddFormattedText("14.New & Next:", TextFormat.Bold);
            p40.AddText(" Date & nội dung - Face to face, fone, e-mail hay mail");
            p40.AddLineBreak();


            Paragraph p41 = doc.LastSection.AddParagraph();
            p41.Format.Font.Size = 10.5;
            p41.AddText("Date ");
            if (string.Format("{0}", customer.CustNewNex01) != "")
            {
                string date1 = customer.CustNewNex01.Split(';')[0] != "" ? customer.CustNewNex01.Split(';')[0] : "";
                string date2 = customer.CustNewNex01.Split(';')[1] != "" ? customer.CustNewNex01.Split(';')[1] : "";
                if (date1 == "" && date2 == "")
                {
                    p41.AddFormattedText("", TextFormat.Underline | TextFormat.Italic);
                }
                else
                {
                    p41.AddFormattedText(date1 + ";" + date2, TextFormat.Underline | TextFormat.Italic);
                }
            }
            p41.AddLineBreak();

            Paragraph p42 = doc.LastSection.AddParagraph();
            p42.Format.Font.Size = 10.5;
            p42.AddText("Date ");
            if (string.Format("{0}", customer.CustNewNex02) != "")
            {
                string date1 = customer.CustNewNex02.Split(';')[0] != "" ? customer.CustNewNex02.Split(';')[0] : "";
                string date2 = customer.CustNewNex02.Split(';')[1] != "" ? customer.CustNewNex02.Split(';')[1] : "";
                if (date1 == "" && date2 == "")
                {
                    p42.AddFormattedText("", TextFormat.Underline | TextFormat.Italic);
                }
                else
                {
                    p42.AddFormattedText(String.Format("{0};{1}", date1, date2), TextFormat.Underline | TextFormat.Italic);
                }
            }
            p42.AddLineBreak();

            Paragraph p43 = doc.LastSection.AddParagraph();
            p43.Format.Font.Size = 10.5;
            p43.AddText("Date ");
            if (string.Format("{0}", customer.CustNewNex03) != "")
            {
                string date1 = customer.CustNewNex03.Split(';')[0] != "" ? customer.CustNewNex03.Split(';')[0] : "";
                string date2 = customer.CustNewNex03.Split(';')[1] != "" ? customer.CustNewNex03.Split(';')[1] : "";
                if (date1 == "" && date2 == "")
                {
                    p43.AddFormattedText("", TextFormat.Underline | TextFormat.Italic);
                }
                else
                {
                    p43.AddFormattedText(date1 + ";" + date2, TextFormat.Underline | TextFormat.Italic);
                }
            }
            p43.AddLineBreak();

            Paragraph p44 = doc.LastSection.AddParagraph();
            p44.Format.Font.Size = 10.5;
            p44.AddFormattedText("15.Date: ", TextFormat.Bold);
            p44.AddFormattedText(string.Format("{0}", customer.CustIsDate), TextFormat.Italic | TextFormat.Underline);
            p44.AddText(string.Format("{0}{1}", "   Signature: ", customer.CustSignature ? "Đã ký" : ""));
            p44.AddFormattedText(customer.studyTravelOther, TextFormat.Italic | TextFormat.Underline);
            p44.AddLineBreak();
            doc.LastSection.AddParagraph();
            if (customer.requirements.Length == 0)
            {
                p44.AddLineBreak();
            }
            if (customer.plan_plan.Length == 0)
            {
                p44.AddLineBreak();
            }
            if (customer.marketing.Length == 0)
            {
                p44.AddLineBreak();
            }
            if (customer.Note_note.Length == 0)
            {
                p44.AddLineBreak();
            }
            if (customer.payment_GD.Length == 0)
            {
                p44.AddLineBreak();
            }
            return doc;
            #endregion
        }

        #region Profile personal
        public static Document PrintCaseProfilePersonal(Document doc, List<profile> profile, Customer customer)
        {
            if (doc == null)
            {
                doc = new Document();
                PDFHelper.AddImage(doc, "Thông Tin Cá Nhân");

            }
            Paragraph p6 = doc.LastSection.AddParagraph();
            p6.Format.Font.Size = 10.5;
            p6.AddFormattedText("Thông tin cá nhân", TextFormat.Bold);
            p6.AddLineBreak();

            Paragraph p1 = doc.LastSection.AddParagraph();
            p1.Format.Font.Size = 10.5;
            p1.AddText("Ngày nhận hồ sơ: ");
            p1.AddFormattedText(customer.ProDate, TextFormat.Italic | TextFormat.Underline);
            p1.AddText("   Người phụ trách: ");
            p1.AddFormattedText(customer.ProCurator, TextFormat.Italic | TextFormat.Underline);
            p1.AddLineBreak();

            Paragraph p2 = doc.LastSection.AddParagraph();
            p2.Format.Font.Size = 10.5;
            p2.AddText("Tên đầy đủ: ");
            p2.AddFormattedText(customer.ProFullName, TextFormat.Italic | TextFormat.Underline);
            p2.AddText("   Nguồn: ");
            p2.AddFormattedText(customer.ProSource, TextFormat.Italic | TextFormat.Underline);
            p2.AddLineBreak();

            Paragraph p3 = doc.LastSection.AddParagraph();
            p3.Format.Font.Size = 10.5;
            p3.AddText("Trường: ");
            p3.AddFormattedText(customer.ProSchool, TextFormat.Italic | TextFormat.Underline);
            p3.AddText("   Chương trình học: ");
            p3.AddFormattedText(customer.ProProgram, TextFormat.Italic | TextFormat.Underline);
            p3.AddLineBreak();

            Paragraph p4 = doc.LastSection.AddParagraph();
            p4.Format.Font.Size = 10.5;
            p4.AddText("Ngày nhập học: ");
            p4.AddFormattedText(customer.ProDateOfAdmission, TextFormat.Italic | TextFormat.Underline);
            p4.AddText("   Ngày phỏng vấn dự kiến: ");
            p4.AddFormattedText(customer.ProscheduledInterviewDate, TextFormat.Italic | TextFormat.Underline);
            p4.AddLineBreak();

            Paragraph p5 = doc.LastSection.AddParagraph();
            p5.Format.Font.Size = 10.5;
            p5.AddText("Khác: ");
            p5.AddFormattedText(customer.ProOther, TextFormat.Italic | TextFormat.Underline);
            p5.AddLineBreak();
            p5.AddLineBreak();

            PrintProfile(doc, profile);

            doc.LastSection.AddParagraph();
            return doc;
        }
        #endregion

        #region profile study
        public static Document PrintCaseProfileStudy(Document doc, List<profile> Profile, Customer customer)
        {
            if (doc == null)
            {
                doc = new Document();
                PDFHelper.AddImage(doc, "Học Tập");
            }
            Paragraph p6 = doc.LastSection.AddParagraph();
            p6.Format.Font.Size = 10.5;
            p6.AddFormattedText("Học tập", TextFormat.Bold);
            p6.AddLineBreak();

            Paragraph p1 = doc.LastSection.AddParagraph();
            p1.Format.Font.Size = 10.5;
            p1.AddText("Tốt nghiệp THPT năm: ");
            p1.AddFormattedText(string.Format("{0}", customer.ProBaccalaureate), TextFormat.Italic | TextFormat.Underline);
            p1.AddLineBreak();

            Paragraph p5 = doc.LastSection.AddParagraph();
            p5.Format.Font.Size = 10.5;
            p5.AddText("Tốt nghiệp ĐH/CĐ năm: ");
            p5.AddLineBreak();

            Paragraph p2 = doc.LastSection.AddParagraph();
            p2.Format.Font.Size = 10.5;
            p2.AddText("Ngành: ");
            p2.AddFormattedText(customer.ProGraduateIndustry, TextFormat.Italic | TextFormat.Underline);
            p2.AddText("   Năm: ");
            p2.AddFormattedText(string.Format("{0}", customer.ProGraduateYear), TextFormat.Italic | TextFormat.Underline);
            p2.AddLineBreak();

            Paragraph p3 = doc.LastSection.AddParagraph();
            p3.Format.Font.Size = 10.5;
            p3.AddText("Làm việc: ");
            p3.AddFormattedText(customer.ProWorking, TextFormat.Italic | TextFormat.Underline);
            p3.AddLineBreak();

            Paragraph p4 = doc.LastSection.AddParagraph();
            p4.Format.Font.Size = 10.5;
            p4.AddText("Khác: ");
            p4.AddFormattedText(customer.ProLearning, TextFormat.Italic | TextFormat.Underline);
            p4.AddLineBreak();
            p4.AddLineBreak();

            PrintProfile(doc, Profile);

            doc.LastSection.AddParagraph();
            return doc;
        }
        #endregion

        #region Profile Finan
        public static Document PrintCaseProfileFinan( Document doc, List<profile> Profile, Customer customer)
        {
            if (doc == null)
            {
                doc = new Document();
                PDFHelper.AddImage(doc, "Tài Chính");
            }
            Paragraph p6 = doc.LastSection.AddParagraph();
            p6.Format.Font.Size = 10.5;
            p6.AddFormattedText("Tài chính", TextFormat.Bold);
            p6.AddLineBreak();

            Paragraph p1 = doc.LastSection.AddParagraph();
            p1.Format.Font.Size = 10.5;
            p1.AddText("Ngành:");
            p1.AddFormattedText(string.Format("{0}", customer.ProFinanIndustry), TextFormat.Italic | TextFormat.Underline);
            p1.AddText("   Vốn:");
            p1.AddFormattedText(string.Format("{0}", customer.ProFinanCapital), TextFormat.Italic | TextFormat.Underline);
            p1.AddLineBreak();

            Paragraph p5 = doc.LastSection.AddParagraph();
            p5.Format.Font.Size = 10.5;
            p5.AddText("Giấy tờ tàu: ");
            p5.AddFormattedText(string.Format("{0}", customer.ProFinanShipPapers), TextFormat.Italic | TextFormat.Underline);
            p5.AddText("   Thuê nhà, đất, xe: ");
            p5.AddFormattedText(string.Format("{0}", customer.ProFinanRental), TextFormat.Italic | TextFormat.Underline);
            p5.AddLineBreak();

            Paragraph p2 = doc.LastSection.AddParagraph();
            p2.Format.Font.Size = 10.5;
            p2.AddText("Khác:");
            p2.AddFormattedText(string.Format("{0}", customer.ProFinanOther), TextFormat.Italic | TextFormat.Underline);
            p2.AddLineBreak();
            p2.AddLineBreak();

            PrintProfile(doc, Profile);

            doc.LastSection.AddParagraph();
            return doc;
        }
        #endregion

        #region Profile Property
        public static Document PrintCaseProfileProperty( Document doc, List<profile> Profile, Customer customer)
        {
            if (doc == null)
            {
                doc = new Document();
                PDFHelper.AddImage(doc, "Tài sản");
            }
            Paragraph p6 = doc.LastSection.AddParagraph();
            p6.Format.Font.Size = 10.5;
            p6.AddFormattedText("Tài sản", TextFormat.Bold);
            p6.AddLineBreak();

            Paragraph p1 = doc.LastSection.AddParagraph();
            p1.Format.Font.Size = 10.5;
            p1.AddText("Nhà đất:");
            p1.AddFormattedText(string.Format("{0}", customer.ProPropertyLand), TextFormat.Italic | TextFormat.Underline);
            p1.AddText("   STK trị giá:");
            p1.AddFormattedText(string.Format("{0}", customer.ProPropertyAccountValue), TextFormat.Italic | TextFormat.Underline);
            p1.AddLineBreak();

            Paragraph p5 = doc.LastSection.AddParagraph();
            p5.Format.Font.Size = 10.5;
            p5.AddText("Xe ô tô/xe tải:");
            p5.AddFormattedText(string.Format("{0}", customer.ProPropertyCar), TextFormat.Italic | TextFormat.Underline);
            p5.AddLineBreak();

            Paragraph p2 = doc.LastSection.AddParagraph();
            p2.Format.Font.Size = 10.5;
            p2.AddText("Khác:");
            p2.AddFormattedText(string.Format("{0}", customer.ProPropertyOther), TextFormat.Italic | TextFormat.Underline);
            p2.AddLineBreak();
            p2.AddLineBreak();

            PrintProfile(doc, Profile);

            doc.LastSection.AddParagraph();
            return doc;
        }
        #endregion

        #region Profile Support
        public static Document PrintCaseProfileSupport( Document doc, List<ProfileProperty> ProfileProperty)
        {
            if (doc == null)
            {
                doc = new Document();
                PDFHelper.AddImage(doc, "Hướng Hỗ trợ");
            }
            Paragraph p6 = doc.LastSection.AddParagraph();
            p6.Format.Font.Size = 10.5;
            p6.AddFormattedText("Hướng Hỗ Trợ", TextFormat.Bold);
            p6.AddLineBreak();
            p6.AddLineBreak();
            Table table = doc.LastSection.AddTable();
            table.Borders.Visible = true;
            table.TopPadding = 5;
            table.BottomPadding = 5;
            Column column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            table.Rows.Height = 20;
            table.Columns.Width= 75;
            Row row = table.AddRow();
            row.Cells[0].AddParagraph("Giấy tờ cần thiết");
            row.Cells[1].AddParagraph("Ngày làm");
            row.Cells[2].AddParagraph("Ngày gửi");
            row.Cells[3].AddParagraph("Đến đâu");
            row.Cells[4].AddParagraph("Cước phí");
            row.Cells[5].AddParagraph("Hoàn tất");
            if (ProfileProperty != null)
            {
                for (int i = 0; i < ProfileProperty.Count; i++)
                {
                    Row rowInfo = table.AddRow();
                    rowInfo.Cells[0].AddParagraph(ProfileProperty[i].PaperRequest);
                    rowInfo.Cells[1].AddParagraph(string.Format("{0}", ProfileProperty[i].OnRequest));
                    rowInfo.Cells[2].AddParagraph(string.Format("{0}", ProfileProperty[i].DateSubmitted));
                    rowInfo.Cells[3].AddParagraph(ProfileProperty[i].ProTo);
                    rowInfo.Cells[4].AddParagraph(ProfileProperty[i].Postage.ToString());
                    rowInfo.Cells[5].AddParagraph(ProfileProperty[i].ProComplete);
                }
            }
            doc.LastSection.AddParagraph();
            return doc;
        }
        #endregion

        #region Profile Finan Source
        public static Document PrintCaseProfileFinanSource(Document doc, List<ProfileFinan> ProfileFinanSource)
        {
            if (doc == null)
            {
                doc = new Document();
                PDFHelper.AddImage(doc, "Nguồn tài chính cần làm");
            }
            Paragraph p6 = doc.LastSection.AddParagraph();
            p6.Format.Font.Size = 10.5;
            p6.AddFormattedText("Nguồn tài chính cần làm", TextFormat.Bold);
            p6.AddLineBreak();
            p6.AddLineBreak();
            Table table = doc.LastSection.AddTable();
            table.Borders.Visible = true;
            table.TopPadding = 5;
            table.BottomPadding = 5;
            Column column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            table.Rows.Height = 20;
            table.Columns.Width = 75;
            Row row = table.AddRow();
            row.Cells[0].AddParagraph("Giấy tờ cần làm");
            row.Cells[1].AddParagraph("Nội dung");
            row.Cells[2].AddParagraph("Ngày làm");
            row.Cells[3].AddParagraph("Ai làm");
            row.Cells[4].AddParagraph("Cước phí");
            row.Cells[5].AddParagraph("Hoàn tất");
            if (ProfileFinanSource != null)
            {
                for (int i = 0; i < ProfileFinanSource.Count; i++)
                {
                    Row rowInfo = table.AddRow();
                    rowInfo.Cells[0].AddParagraph(ProfileFinanSource[i].PaperRequest);
                    rowInfo.Cells[1].AddParagraph(ProfileFinanSource[i].Content);
                    rowInfo.Cells[2].AddParagraph(string.Format("{0}", ProfileFinanSource[i].OnDate));
                    rowInfo.Cells[3].AddParagraph(ProfileFinanSource[i].WHoDo);
                    rowInfo.Cells[4].AddParagraph(ProfileFinanSource[i].Postage.ToString());
                    rowInfo.Cells[5].AddParagraph(ProfileFinanSource[i].ProComplete);
                }
            }
            doc.LastSection.AddParagraph();
            return doc;
        }
        #endregion

        #region FeesShedule
        public static Document PrintCaseProfileFeesShedule(Document doc, List<FeesSchedule> feesShedule)
        {
            if (doc == null)
            {
                doc = new Document();
                PDFHelper.AddImage(doc, "Kế hoạch chi phí");
            }
            Paragraph p6 = doc.LastSection.AddParagraph();
            p6.Format.Font.Size = 10.5;
            p6.AddFormattedText("FeesShedule", TextFormat.Bold);
            p6.AddLineBreak();
            p6.AddLineBreak();
            Table table = doc.LastSection.AddTable();
            table.Borders.Visible = true;
            table.TopPadding = 5;
            table.BottomPadding = 5;
            Column column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            table.Rows.Height = 20;
            table.Columns.Width = 75;
            Row row = table.AddRow();
            row.Cells[0].AddParagraph("Loại phí");
            row.Cells[1].AddParagraph("Khóa học");
            row.Cells[2].AddParagraph("Số tiền USD");
            row.Cells[3].AddParagraph("Số tiền VND");
            row.Cells[4].AddParagraph("Đã đóng USD");
            row.Cells[5].AddParagraph("Đã đóng VND");
            decimal AmountUSD = 0;
            decimal AmountVND = 0;
            decimal HaveToPayUSD = 0;
            decimal HaveToPayVND = 0;
            if (feesShedule != null)
            {
                for (int i = 0; i < feesShedule.Count; i++)
                {
                    Row rowInfo = table.AddRow();
                    rowInfo.Cells[0].AddParagraph(feesShedule[i].FessName);
                    rowInfo.Cells[1].AddParagraph(feesShedule[i].CoursName);
                    rowInfo.Cells[2].AddParagraph(CommonHelper.FormatNumber(feesShedule[i].AmountUSD)); 
                    AmountUSD += feesShedule[i].AmountUSD;
                    rowInfo.Cells[3].AddParagraph(CommonHelper.FormatNumber(feesShedule[i].AmountVND));
                    AmountVND += feesShedule[i].AmountVND;
                    rowInfo.Cells[4].AddParagraph(CommonHelper.FormatNumber(feesShedule[i].HaveToPayUSD));
                    HaveToPayUSD += feesShedule[i].HaveToPayUSD;
                    rowInfo.Cells[5].AddParagraph(CommonHelper.FormatNumber(feesShedule[i].HaveToPayVND));
                    HaveToPayVND += feesShedule[i].HaveToPayVND;
                }
                Row rowInfoTotal = table.AddRow();
                rowInfoTotal.Cells[0].AddParagraph("");
                rowInfoTotal.Cells[1].AddParagraph("Tổng cộng");
                rowInfoTotal.Cells[2].AddParagraph(CommonHelper.FormatNumber(AmountUSD));
                rowInfoTotal.Cells[3].AddParagraph(CommonHelper.FormatNumber(AmountVND));
                rowInfoTotal.Cells[4].AddParagraph(CommonHelper.FormatNumber(HaveToPayUSD));
                rowInfoTotal.Cells[5].AddParagraph(CommonHelper.FormatNumber(HaveToPayVND));
            }
            doc.LastSection.AddParagraph();
            return doc;
        }
        #endregion

        #region profile table
        public static void PrintProfile(Document doc, List<profile> Profile)
        {
            Table table = doc.LastSection.AddTable();
            table.Borders.Visible = true;
            table.TopPadding = 5;
            table.BottomPadding = 5;
            Column column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            column = table.AddColumn();
            column.Format.Alignment = ParagraphAlignment.Center;
            table.Rows.Height = 20;
            table.Columns.Width = 75;
            Row row = table.AddRow();
            row.Cells[0].AddParagraph("Giấy tờ cần thiết");
            row.Cells[1].AddParagraph("Bản gốc");
            row.Cells[2].AddParagraph("Sao y");
            row.Cells[3].AddParagraph("Ngày yêu cầu");
            row.Cells[4].AddParagraph("Ngày nộp");
            row.Cells[5].AddParagraph("Ghi chú");
            if (Profile != null)
            {
                for (int i = 0; i < Profile.Count; i++)
                {
                    Row rowInfo = table.AddRow();
                    rowInfo.Cells[0].AddParagraph(Profile[i].ObjectName);
                    if (Profile[i].OriginalCopy)
                    {
                        rowInfo.Cells[1].AddParagraph("Bản gốc");
                        rowInfo.Cells[2].AddParagraph("");
                    }
                    if(Profile[i].duplicate)
                    {
                        rowInfo.Cells[1].AddParagraph("");
                        rowInfo.Cells[2].AddParagraph("Sao y");
                    }
                    rowInfo.Cells[3].AddParagraph(string.Format("{0}", Profile[i].OnRequest));
                    rowInfo.Cells[4].AddParagraph(string.Format("{0}", Profile[i].DateSubmitted));
                    rowInfo.Cells[5].AddParagraph(Profile[i].Note);
                }
            }
        }
        #endregion

        #region Print file
        public static void PrintFile(Document doc, string filePath)
        {
            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always) { Document = doc };
            renderer.RenderDocument();
            renderer.PdfDocument.Save(filePath);
        }
        #endregion

        public static void PrintCustomerToPdf(List<Customer> customerCollection, string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            Document doc = new Document();
            Section section = doc.AddSection();
            int customerNumber = 1;
            int custCount = customerCollection.Count;
            foreach (var cust in customerCollection)
            {
                Paragraph p1 = section.AddParagraph(String.Format("{0}. {1}", customerNumber, cust.CustName));
                p1.Format.Font.Bold = true;
                p1.Format.Font.Color = Colors.Black;

                section.AddParagraph();

                section.AddParagraph(HtmlHelper.StripTags(HtmlHelper.ConvertHtmlToPlainText(cust.CustCaseWork)));

                section.AddParagraph();

                customerNumber++;

                if (customerNumber <= custCount)
                {
                    section.AddPageBreak();
                }
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always) { Document = doc };
            renderer.RenderDocument();
            renderer.PdfDocument.Save(filePath);
        }

        #endregion

        #region Properties
        /// <summary>
        /// Gets a file path to PDF logo
        /// </summary>
        public static string LogoFilePath
        {
            get
            {
                return HttpContext.Current.Request.PhysicalApplicationPath + "images/pdflogo.img";
            }
        }
        protected static XRect GetRect(int index)
        {
            XRect rect = new XRect(0, 0, A4Width / 3 * 0.9, A4Height / 3 * 0.9) { X = (index % 3) * A4Width / 3 + A4Width * 0.05 / 3, Y = (index / 3) * A4Height / 3 + A4Height * 0.05 / 3 };
            return rect;
        }
        protected static string FormattedText(string arg)
        {
            if (CommonHelper.IsBlank(arg))
                return Append((int)A4Width);
            return arg + Append((int)A4Width - arg.Length);
        }
        protected static string Append(int N)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < N; i++)
            {
                sb.Append("_");
            }
            return sb.ToString();
        }
        static double A4Width = XUnit.FromCentimeter(21).Point;
        static double A4Height = XUnit.FromCentimeter(29.7).Point;
        #endregion
        #region Image
        protected static void AddImage(Document doc, string title)
        {
            doc.DefaultPageSetup.MirrorMargins = true;
            doc.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(2.5);
            doc.DefaultPageSetup.RightMargin = Unit.FromCentimeter(2.5);
            doc.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            doc.DefaultPageSetup.BottomMargin = Unit.FromCentimeter(2);
            Section section = doc.AddSection();
            section.PageSetup.TopMargin = Unit.FromCentimeter(3);
            ///image
            Paragraph paraHeader = section.Headers.Primary.AddParagraph();
            paraHeader.AddImage(m_urlImage);
            paraHeader.Format.Alignment = ParagraphAlignment.Center;

            //Tile
            Paragraph paraTitle = section.AddParagraph();
            paraTitle.AddText(title.ToUpper());
            paraTitle.Format.Font.Size = 15;
            paraTitle.Format.Font.Bold = true;
            paraTitle.Format.Font.Color = Colors.DarkBlue;
            paraTitle.Format.Alignment = ParagraphAlignment.Center;

            section.AddParagraph();
        }
        #endregion
    }
}
